import 'package:flutter/material.dart';
import 'package:flutter_eve_plugin/components/health/text_ex.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/archives/archives_get_dialog.dart';
import 'package:flutter_eve_plugin/constants/font_family.dart';
import 'package:flutter_eve_plugin/constants/font_weight.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/achieves/archieves_weapon_entity.dart';
import 'package:flutter_eve_plugin/pages/ye_xiu/archives/actions.dart';
import 'package:flutter_eve_plugin/store/main.dart';
import 'package:flutter_eve_plugin/store_vm/app_vm.dart';
import 'package:flutter_eve_plugin/store_vm/ye_xiu/archives/main.dart';
import 'package:flutter_eve_plugin/store_vm/ye_xiu/main.dart';
import 'package:flutter_eve_plugin/utils/image_util.dart';
import 'package:flutter_eve_plugin/utils/screen_util.dart';
import 'package:flutter_redux/flutter_redux.dart';

//形态解锁
class ArchivesAdvancedBtnWidget extends StatelessWidget {
  final ArchievesWeaponEntity archievesWeaponEntity;

  const ArchivesAdvancedBtnWidget({Key key, this.archievesWeaponEntity})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    int needGold = 0;
    List<ArchievesWeaponUpgradegood> formUpgradeGood =
        archievesWeaponEntity.formUpgradeGoods;
    if (formUpgradeGood != null) {
      for (ArchievesWeaponUpgradegood good in formUpgradeGood) {
//          升级所需金币
        if (good?.goodsType == 4) {
          needGold = good?.num ?? 0;
        }
      }
    }

//    return StoreConnector<AppState, AppStateViewModel>(
//        converter: (store) => AppStateViewModel(state: store.state),
    return StoreConnector<AppState, AppStateViewModel>(converter: (store) {
      return AppStateViewModel(yeXiuStateViewModel: YeXiuStateViewModel(
          archivesStateViewModel: ArchivesStateViewModel(upFormLevel: () {
        store.dispatch(upgradeForm(context));
      })));
    }, builder: (context, vm) {
      return Positioned(
        bottom: setRatio(22),
        left: setRatio(125),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            GestureDetector(
              onTap: () =>
                  vm.yeXiuStateViewModel.archivesStateViewModel.upFormLevel(),
//                    showAlertDialog(context);
              child: Container(
                width: setRatio(110),
                height: setRatio(42),
                decoration: BoxDecoration(
                    image: DecorationImage(
                        image: AssetImage(imageUtilYeXiu(
                            'archives/icon_archivers_upgrade@3x')))),
                child: Padding(
                  padding:
                      EdgeInsets.only(top: setRatio(8), left: setRatio(41)),
                  child: TextEx(
                    '解锁',
                    shadow: Color(0xCCCB8829),
                    style: TextStyle(
                        shadows: [
                          BoxShadow(
                              color: Color(0xCCCB8829),
                              offset: Offset(0, setRatio(2)),
                              blurRadius: setRatio(2))
                        ],
                        fontFamily: FontFamily.PINGFANG,
                        fontWeight: FontWeightCustom.PF_Medium,
                        fontSize: setTextSp(15),
                        color: Color(0xFFFFFFFF)),
                  ),
                ),
              ),
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                Image.asset(
                  imageUtilYeXiu('main/icon_nav_right_coin@3x'),
                  width: setRatio(20),
                  height: setRatio(20),
                ),
                Text(
                  '$needGold',
                  style: TextStyle(
                      decoration: TextDecoration.none,
                      fontFamily: FontFamily.PINGFANG,
                      fontWeight: FontWeightCustom.PF_Medium,
                      fontSize: setTextSp(13),
                      color: Color(0xFFFFFFFF)),
                )
              ],
            )
          ],
        ),
      );
    });
  }

  void showAlertDialog(BuildContext context) {
    showDialog(
      context: context,
      barrierDismissible: false,
      builder: (BuildContext context) {
        return ArchivesGetDialog();
      },
    );
  }
}
